package com.qf.fmall.index.controller;

import com.qf.fmall.index.entity.Category;
import com.qf.fmall.index.entity.IndexImg;
import com.qf.fmall.index.entity.Product;
import com.qf.fmall.index.service.ICategoryService;
import com.qf.fmall.index.service.IIndexImgService;
import com.qf.fmall.index.service.IProductService;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author weijy
 * @since 2024-01-16
 */
@CrossOrigin // 解决跨域
@RestController
@RequestMapping("/index")
public class IndexController {


    @Autowired
    private ICategoryService categoryService;

    @Autowired
    private IProductService productService;

    @Autowired
    private IIndexImgService indexImgService;



    @RequestMapping("/indeximg")
    public ResultVo indeximg() {


        List<IndexImg> imgList = indexImgService.getImgList();

        if (imgList == null) {
            return new ResultVo(-10000, "error", null);
        } else {
            ResultVo resultVo = new ResultVo(10000, "success", imgList);
            return resultVo;
        }
    }

    @RequestMapping("/category-list")
    public ResultVo categoryList() {

        List<Category> categoryList = categoryService.getCategoryListPro();

        if (categoryList == null) {
            return new ResultVo(-10000, "error", null);
        } else {
            return new ResultVo(10000, "success", categoryList);
        }
    }

    @RequestMapping("/category-recommends")
    public ResultVo categoryRecommends(){

        List<Category> categoryList = categoryService.categoryRecommendsList();

        if (categoryList == null) {
            return new ResultVo(-10000, "error", null);
        } else {
            return new ResultVo(10000, "success", categoryList);
        }
    }



    @RequestMapping("/list-recommends")
    public ResultVo listRecommends() {

        List<Product> productList = productService.getListRecommends();

        if (productList == null) {
            return new ResultVo(-10000, "error", null);
        } else {
            return new ResultVo(10000, "success", productList);
        }
    }


}
